/*
 * To change this template, choose Tools | Templates
* and open the template in the editor.
 */
package com.benimetum.test;

import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class xmlTester {
    public static void main(String argv[]){
        
       try{
           File fXmlFile = new File("ders9.xml");
		DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
		Document doc = dBuilder.parse(fXmlFile);
		doc.getDocumentElement().normalize();
                System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
                NodeList nList = doc.getElementsByTagName("Ders");
		System.out.println("-----------------------");
       
               for (int temp = 0; temp < nList.getLength(); temp++) {
 
		   Node nNode = nList.item(temp);
		   if (nNode.getNodeType() == Node.ELEMENT_NODE) {
 
		      Element eElement = (Element) nNode;
 
		      System.out.println("Kod : " + getTagValue("Kod", eElement));
                      String kod = getTagValue("Kod", eElement);
		      System.out.println("Ad : " + getTagValue("DersAd", eElement));
	              System.out.println("Sube : " + getTagValue("subeKod", eElement));
                      String skod = getTagValue("subeKod", eElement);
		      System.out.println("Ogretmen : " + getTagValue("ogretmen", eElement));
                      System.out.println("OgretmenID : " + getTagValue("ogretmenID", eElement));
                      System.out.println("Liste : " + getTagValue("liste", eElement));
                      System.out.println("-----------------------");
                      NodeList nList2 = doc.getElementsByTagName("ogrenciler"+kod+skod);
                      for(int temp2=0; temp2 < nList2.getLength(); temp2++){
                            Node nNode2 = nList2.item(temp2);
                            if(nNode2.getNodeType()==Node.ELEMENT_NODE){
                            Element eElement2 = (Element) nNode2;     
                                 System.out.println("no : " + getTagValue("no", eElement2));
                                 System.out.println("ad : " + getTagValue("ad", eElement2));
                                 System.out.println("bolum : " + getTagValue("bolum", eElement2));
                                 System.out.println("sinif : " + getTagValue("sinif", eElement2));
                                 System.out.println("mail : " + getTagValue("mail", eElement2));
                            
                            }
                        }  
                      
                   }
                    System.out.println("-----------------------");
		}
       }
       catch (Exception e) {
	  }
    
    
    
    }

    private static String getTagValue(String sTag, Element eElement){
        NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes();
        Node nValue = (Node) nlList.item(0);
        return nValue.getNodeValue();
       
    }
    
}
